package gui.buttons 
{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import gui.PositionInfo;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class LabelButton extends BaseButton
	{
		protected var _label:String;
		public var textField:TextField;
		private var _textPosition:PositionInfo;
		public function LabelButton(parent:DisplayObjectContainer = null, 
										xpos:Number = 0, ypos:Number =  0) 
		{
			super(parent, xpos, ypos);
		}
		
		override protected function onComponentInit():void 
		{
			super.onComponentInit();
			textField = new TextField();
			textField.mouseEnabled = false;
			textField.selectable = false;
			textField.width = 0;
			textField.autoSize = TextFieldAutoSize.RIGHT;
			addChild(textField);
			textPosition = new PositionInfo();
		}
		
		
		override protected function onInvalidate(e:Event):void 
		{
			setTextPosition();
			super.onInvalidate(e);
		}
		
		protected function setTextPosition():void 
		{
			textField.x = textPosition.getPosX(width, textField.width);
			textField.y = textPosition.getPosY(height, textField.height);
		}
		
		
		public function get label():String 
		{
			return _label;
		}
		
		public function set label(value:String):void 
		{
			_label = value;
			textField.text = value;
			invalidate();
		}
		
		public function get textPosition():PositionInfo 
		{
			return _textPosition;
		}
		
		public function set textPosition(value:PositionInfo):void 
		{
			_textPosition = value;
			invalidate();
		}
		
		
	
	}

}